//
//  SMSRequestProvider.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/26.
//


#import "Item5UserBindCardRequestProvider.h"
#import "Item5GetUserBindCardRequest.h"
#import "Item5UpdateUserBindCardRequest.h"
//#import "Base64Help.h"

@implementation Item5UserBindCardRequestProvider

// 获取用户信息
+ (void)requestUserBindCardWithNewCard:(BOOL)isNewCard
                               success:(void(^)(NSDictionary *dict))success
                               failure:(void(^)(YTKRequest *request))failure {
    Item5GetUserBindCardRequest *request = [Item5GetUserBindCardRequest new];
    //是否添加新卡（app认证项给0，h5添加新卡给1）
    //    request.crosses = @(isNewCard).stringValue;
    //#ifdef DEBUG
    //    request.scenery = @"2";
    //#endif
    [request startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *dict = request.responseObject;
        if (![dict isKindOfClass:NSDictionary.class]) {
            !failure ?: failure(request);
            return;
        }
        if ([dict[@"weeps"] intValue] == 0) {
            // 成功
            !success ?: success(dict[@"bounding"]);
        } else {
            !failure ?: failure(request);
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        !failure ?: failure(request);
    }];
}

// 保存用户信息
+ (void)requestUpdateBindCardInfoWithProductId:(NSString *)productId
                                      cardType:(NSString *)cardType
                                          info:(NSDictionary *)info
                                       success:(void(^)(NSDictionary *dict))success
                                       failure:(void(^)(YTKRequest *request))failure {
    Item5UpdateUserBindCardRequest *request = [Item5UpdateUserBindCardRequest new];
    request.scenery = productId;
    request.monthly = cardType;
    request.info = info;
#ifdef DEBUG
    request.scenery = @"2";
    request.monthly = @"ewallet";
#endif
    [request startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *dict = request.responseObject;
        if (![dict isKindOfClass:NSDictionary.class]) {
            !failure ?: failure(request);
            return;
        }
        if ([dict[@"weeps"] intValue] == 0) {
            // 成功
            !success ?: success(dict[@"bounding"]);
        } else {
            !failure ?: failure(request);
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        !failure ?: failure(request);
    }];
}


@end
